package com.example.time;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class time {
    public static void main(String[] args) {

        //        SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
////        yyyy-mm-DD
//        String format = f.format(param.getLOCALREQTIME().toGregorianCalendar().getTime());
//        System.out.println(format);
//        Date parse = new Date();
//        try {
//             parse = f.parse(format);
//            System.out.println(parse);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }

        String a="2021-12-12 9:03:23";
        SimpleDateFormat f = new SimpleDateFormat("yyyy-mm-DD HH:mm:ss");
        try {
            Date nows =  f.parse(a);
            System.out.println(nows);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date now = null;
        try {
            now = f.parse(a);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        DateFormat d1 = DateFormat.getDateInstance(); //默认语言（汉语）下的默认风格（MEDIUM风格，比如：2008-6-16 20:54:53）
        String str1 = d1.format(now);
        DateFormat d3 = DateFormat.getDateTimeInstance();
        String str2 = d3.format(now);
        XMLGregorianCalendar gcc = null;
        XMLGregorianCalendar gcc2 = null;
//        try {
//            gcc = DatatypeFactory.newInstance().newXMLGregorianCalendar(str1);
//            gcc2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(str2);
//        } catch (DatatypeConfigurationException e) {
//            e.printStackTrace();
//        }
//        System.out.println(gcc);
//        System.out.println(gcc2);

        Date ss = null;
        System.out.println(ss);
        ss = new Date();
        System.out.println(ss);


         XMLGregorianCalendar localrestime;

        try {
            GregorianCalendar gcal = new GregorianCalendar();
            XMLGregorianCalendar xgcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
            System.out.println(gcal);
            System.out.println("xgcal=" + xgcal.toString());

            Date date=new Date();
            gcal.setTime(date);
            xgcal= DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
            System.out.println("xgcal="+xgcal.toString());


            GregorianCalendar gcals = new GregorianCalendar();
            Date dates = new Date(2021-01-01);
            gcals.setTime(dates);
            localrestime = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
            System.out.println(localrestime);

            SimpleDateFormat ff = new SimpleDateFormat("yyyy-mm-DD");
            Date datet = ff.parse("2022-01-10 9:03:23");
            System.out.println(datet);
            System.out.println(ff.format(new Date()));
            GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
            gc.setTime(datet);
            localrestime = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
            System.out.println(localrestime);




        }catch (Exception e){

        }
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        XMLGregorianCalendar gc = null;
        XMLGregorianCalendar gccs = null;
        try {
            gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);

            //保留年月日去掉时间后的格式
            gc.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
            System.out.println("去掉时间后的格式:"+gc.toString());

            gc.setTime(DatatypeConstants.FIELD_UNDEFINED,
                    DatatypeConstants.FIELD_UNDEFINED,
                    DatatypeConstants.FIELD_UNDEFINED,
                    DatatypeConstants.FIELD_UNDEFINED);
            System.out.println("转换格式保留年月日：" + gc.toString());
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
        }


        Date date = null;

        Date date1 = new Date();

        Calendar c1 = Calendar.getInstance();
        XMLGregorianCalendar zs = null;
        //获取年份
        int year = c1.get(Calendar.YEAR);
        //获取月份
        int month = c1.get(Calendar.MONTH)+1;
        //获取日期
        int dates = c1.get(Calendar.DATE);
//        XMLGregorianCalendar zs = year,month,dates;
//        GregorianCalendar(year,month,dates);
//
//        date.setYear(year);
//        date.setMonth(month);
//        date.setDate(dates);
        System.out.println(date);
    }
}
